import 'package:banyou_app/app/config/colors.dart';
import 'package:banyou_app/app/widget/app_bar_widget.dart';
import 'package:banyou_app/app/widget/multi_row_input_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/adddongtai_controller.dart';

class AdddongtaiView extends GetView<AdddongtaiController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget(titleStr: '发布动态'),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 12),
        child: Column(
          children: [
            Container(
              color: ColorConfig.white,
              child: MultiRowInput('在这里输入正文~', (str) {
                print(str);
                controller.str = str;
              }, 150, TextEditingController(text: '')),
            ),
            Container(
              color: Color(0xFFEDEDED),
              height: 1,
              width: 1.sw,
            ),
            Obx(() => Container(
                  padding: EdgeInsets.all(10),
                  child: GridView.builder(
                    physics: NeverScrollableScrollPhysics(),
                    shrinkWrap: true,
                    clipBehavior: Clip.none,
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        childAspectRatio: 1,
                        crossAxisCount: 4,
                        crossAxisSpacing: 15.0,
                        mainAxisSpacing: 15.0),
                    itemBuilder: (BuildContext context, int index) {
                      bool showAdd = controller.imgsList.length == index;
                      return Container(
                          clipBehavior: Clip.none,
                          child: showAdd
                              ? InkWell(
                                  onTap: () {
                                    controller.addImg();
                                  },
                                  child: Image.asset('assets/images/upimg.png'),
                                )
                              : Stack(
                                  clipBehavior: Clip.none,
                                  children: [
                                    Positioned.fill(
                                      child: Image.file(
                                        controller.imgsList[index],
                                        fit: BoxFit.fill,
                                      ),
                                    ),
                                    Positioned(
                                        top: -10,
                                        right: -10,
                                        child: InkWell(
                                          onTap: () {
                                            controller.deleteImg(index);
                                          },
                                          child: Image.asset(
                                            'assets/images/delete_icon.png',
                                            width: 20,
                                          ),
                                        )),
                                  ],
                                ));
                    },
                    itemCount: (controller.imgsList.length) >= 1
                        ? 1
                        : controller.imgsList.length + 1,
                  ),
                )),
            Spacer(),
            InkWell(
              onTap: () {
                controller.add();
              },
              child: SafeArea(
                child: Container(
                  margin: EdgeInsets.symmetric(horizontal: 51),
                  height: 45,
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                        begin: Alignment.centerLeft,
                        end: Alignment.centerRight,
                        colors: [
                          Color(0xFFF52EC5),
                          Color(0xFFFF8A33),
                        ]),
                    borderRadius: BorderRadius.circular(20),
                  ),
                  child: Center(
                    child: Text(
                      "发布",
                      style: TextStyle(
                          color: ColorConfig.white,
                          fontSize: 16,
                          fontWeight: FontWeight.w500),
                    ),
                  ),
                ),
              ),
            ),
            SizedBox(height: 20)
          ],
        ),
      ),
    );
  }
}
